<?php
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::prefix('backend')->group(function () {
    /**
     * 登录相关
     */
    Route::prefix('auth')->group(function () {
        Route::post('login', 'AuthController@login')->name('auth.login'); //登录
        Route::get('logout', 'AuthController@logout')->name('auth.logout'); //退出登录
        Route::get('refresh', 'AuthController@logout')->name('auth.refresh'); //刷新token
    });

    // 登录才能访问
    Route::middleware(['auth:backend'])->group(function () {
        /**
         * 管理员用户相关
         */
        Route::prefix('admin-user')->group(function () {
            Route::get('info', 'AdminUserController@info')->name('admin-user.info'); //管理员信息
            Route::get('list', 'AdminUserController@list')->name('admin-user.list'); //管理员列表
            Route::post('create', 'AdminUserController@create')->name('admin-user.create'); //创建管理员
            Route::post('update', 'AdminUserController@update')->name('admin-user.update'); //编辑管理员
            Route::post('assign-roles', 'AdminUserController@assignRoles')->name('admin-user.assign-roles'); //给管理员分配角色
            Route::get('delete/{id}', 'AdminUserController@delete')->name('admin-user.delete'); //删除管理员
            Route::get('get-user-menus', 'AdminUserController@getUserMenus')->name('admin-user.get-user-menus'); //获取管理员菜单
            Route::get('get-user-roles', 'AdminUserController@getUserRoles')->name('admin-user.get-user-roles'); //获取管理员权限
        });

        /**
         * 角色相关
         */
        Route::prefix('role')->group(function () {
            Route::get('list', 'RoleController@list')->name('role.list'); //角色列表
            Route::get('all', 'RoleController@all')->name('role.all'); //所有角色
            Route::post('create', 'RoleController@create')->name('role.create'); //创建角色
            Route::post('update', 'RoleController@update')->name('role.update'); //编辑角色
            Route::get('delete/{id}', 'RoleController@delete')->name('role.delete'); //删除角色
            Route::post('assign-permissions', 'RoleController@assignPermissions')->name('role.assign-permissions'); //给角色分配权限
        });

        /**
         * 权限相关
         */
        Route::prefix('permission')->group(function () {
            Route::get('list', 'PermissionController@list')->name('permission.list'); //权限列表
            Route::get('all', 'PermissionController@all')->name('permission.all'); //所有权限
            Route::get('role-permissions', 'PermissionController@rolePermissions')->name('permission.role-permissions'); //所有权限
            Route::post('create', 'PermissionController@create')->name('permission.create'); //创建权限
            Route::post('update', 'PermissionController@update')->name('permission.update'); //编辑权限
            Route::get('delete/{id}', 'PermissionController@delete')->name('permission.delete'); //删除权限
        });

        /**
         * 菜单相关
         */
        Route::prefix('menu')->group(function () {
            Route::get('tree', 'MenuController@tree')->name('menu.tree'); //菜单树
            Route::post('create', 'MenuController@create')->name('permission.create'); //创建权限
            Route::post('update', 'MenuController@update')->name('permission.update'); //编辑权限
            Route::get('delete/{id}', 'MenuController@delete')->name('permission.delete'); //删除权限
        });
    });
});
